package com.six.JacksonOperation;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.six.entity.Person;

import java.util.Arrays;

/**
 * ClassName:JavaToJson
 * Package:com.six.JacksonOperation
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2023/7/27 - 23:04
 * @Version:v1.0
 */
//java对象转换为json格式
public class JavaToJson {
    public static void main(String[] args) throws JsonProcessingException {
        Person person = new Person();
        person.setName("swx");
        person.setAge(18);
        person.setSkillsList(Arrays.asList("java","python","php"));
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(person);
        //{"name":"swx","age":18,"skillsList":["java","python","php"]}
        System.out.println(json);
    }

}
